package info.bond.rp.experiments;

import info.bondtnt.labs.model.research.BoundedDoubleParameter;
import info.bondtnt.labs.model.research.NamedDoubleParameter;
import info.bondtnt.labs.model.research.ParametersList;
import info.bondtnt.labs.model.research.ResearchFactory;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.EList;


public class ExperimentsDataGeneratorImpl implements ExperimentsDataGenerator {
	
	private List<BoundedDoubleParameter> boundedDoubleParameterList;

	public ExperimentsDataGeneratorImpl() {
		this.boundedDoubleParameterList = new ArrayList<BoundedDoubleParameter>();
	}
	
	@Override
	public void add(BoundedDoubleParameter boundedParam) {
		boundedDoubleParameterList.add(boundedParam);
	}

	@Override
	public List<ParametersList<NamedDoubleParameter>> generateParametersList() {
		List<ParametersList<NamedDoubleParameter>> resultingList = new ArrayList<ParametersList<NamedDoubleParameter>>();
		List<EList<Double>> allValuesList = new ArrayList<EList<Double>>();
		List<Integer> indexesList = new ArrayList<Integer>();
		
		int totalCountOfParamsCombinations = 1;
		for (BoundedDoubleParameter boundedDoubleParameter : boundedDoubleParameterList) {
			Integer countOfValues = boundedDoubleParameter.countOfValues();
			totalCountOfParamsCombinations = totalCountOfParamsCombinations * countOfValues;
			EList<Double> allValues = boundedDoubleParameter.allValues();
			allValuesList.add(allValues);
			indexesList.add(0);
		}
		
		while (totalCountOfParamsCombinations > 0) {
			totalCountOfParamsCombinations--;
			
			// collect all param values to resultingList
			ParametersList<NamedDoubleParameter> parametersList = ResearchFactory.eINSTANCE.createParametersList();
			for (int i = 0; i < allValuesList.size(); i++) {
//			for (Integer index : indexesList) {
				EList<Double> list = allValuesList.get(i);
				Integer index = indexesList.get(i);
				Double value = list.get(index);
				NamedDoubleParameter namedParam = ResearchFactory.eINSTANCE.createNamedDoubleParameter();
//				namedParam.setName(name);
				namedParam.setValue(value);
				parametersList.addParameter(namedParam );
			}
			
			int indexOfParam = 0;
			BoundedDoubleParameter boundedDoubleParameter = boundedDoubleParameterList.get(indexOfParam);
			
			Integer countOfValues = boundedDoubleParameter.countOfValues();
			totalCountOfParamsCombinations = totalCountOfParamsCombinations * countOfValues;
		}
		
		return null;
	}
}
